<%@ page language="java" import="java.util.*,java.sql.*,com.ruohi.util.dbutil.*,com.ruohi.util.common.*" pageEncoding="UTF-8"%>
<%
	String category = CommonString.getFormatPara(request.getParameter("category"));
	String []categoryArr = category.split(",");
	Map valueMap = new HashMap();
	for(int i = 0; i < categoryArr.length; i++){
		valueMap.put(categoryArr[i],true);
	}
	List<Map> categoryList = (List)application.getAttribute("giftCategoryList");
	
	StringBuffer tree = new StringBuffer();
	for(int i = 0;categoryList != null && i < categoryList.size();i++){
		String pid = "0";
		if(categoryList.get(i).get("no").toString().length() > 3){
			pid = categoryList.get(i).get("no").toString().substring(0,categoryList.get(i).get("no").toString().length()-3);
		}
		if(null!=valueMap.get(categoryList.get(i).get("no").toString())){
			tree.append("{ id:'"+categoryList.get(i).get("no").toString()+"', pId:'"+pid+"', name:'"+categoryList.get(i).get("name")+"',open:true,checked:true},");
		}else{
			tree.append("{ id:'"+categoryList.get(i).get("no").toString()+"', pId:'"+pid+"', name:'"+categoryList.get(i).get("name")+"',open:true},");
		}
	}
	if(tree == null){
		tree = new StringBuffer();
	}
	String treeStr = "";
	treeStr = tree.toString().substring(0,tree.toString().length()-1);
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title><%=Env.getInstance().getProperty("project_name") %></title>
<link rel="stylesheet" type="text/css" href="/plugin/tree/ztree/zTreeStyle/zTreeStyle.css" />
</head>

<body>
<ul id="ztree" style="margin-top: 3px;" class="ztree">
</ul>
</body>
</html>
<script src="/plugin/jquery/jquery.min.js" type="text/javascript"></script>
<script src="/plugin/tree/ztree/jquery.ztree.all-3.1.js" type="text/javascript"></script>

<script type="text/javascript">

var zTreeNodes = [
	<%=treeStr %>
];

var setting = {
	view: {
		dblClickExpand: false,
		showLine: true,
		selectedMulti: false,
		expandSpeed: ($.browser.msie && parseInt($.browser.version)<=6)?"":"fast"
	},
	data: {
		simpleData: {
			enable:true,
			idKey: "id",
			pIdKey: "pId",
			rootPId: "0"
		}
	},
	check: {
		enable : true
	}
};
var zTree = jQuery.fn.zTree.init(jQuery("#ztree"), setting, zTreeNodes);
function doSub(dialog){
	var chks = zTree.getCheckedNodes(true);
	var category = "";
	var categoryName = "";
	for(var i=0;i<chks.length;i++){
		category += chks[i].id+",";
		categoryName += chks[i].name+",";
	}
	if(null!=category&&""!=category&&category.indexOf(",")!=-1){
		category = category.substring(0,category.length-1);
		categoryName = categoryName.substring(0,categoryName.length-1);
	}
	
	parent.document.getElementById("zd_category").value = category;
	parent.document.getElementById("zd_category_name").value = categoryName;
	parent.jQuery.ligerDialog.hide();
}
</script>